package com.project.service.impl;

import com.project.service.MailService;
import com.project.util.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Date;

@Slf4j
@Service
public class MyJob implements Job {


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {

            executeTask(jobExecutionContext);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //java fhadmin.cn
    private static void executeTask(JobExecutionContext jobExecutionContext) throws SchedulerException, IOException {
        //JobExecutionContext 类提供了调度应用的一些信息；
        //Job 运行时的信息保存在 JobDataMap 实例中。

        // 调用接口发送邮件
        MailService mailService = BeanUtils.getBean(com.project.service.MailService.class);
        mailService.sendWeeklyReport();

        // 打印日志信息
        JobKey key = jobExecutionContext.getJobDetail().getKey();
        log.info(key.toString() + " Scheduled task is executing");
    }

}
